package ru.sis.shop.model;

import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotBlank;

import com.google.common.base.Preconditions;

/**
 * Item in the shop.
 * 
 * @author sis
 */
@Entity
@Table(name = "item")
public class Item {
	/**
	 * id field.
	 */
	private long id;

	/**
	 * name of item.
	 */
	private String name;

	/**
	 * descriptions of this item.
	 */
	private String description;

	/**
	 * general image of item.
	 */
	private String mainImage;

	/**
	 * additional images of this item.
	 */
	private Set<String> images = new HashSet<>();

	/**
	 * cost.
	 */
	private int cost;

	/**
	 * height of item.
	 */
	private BigDecimal height;

	/**
	 * width of item.
	 */
	private BigDecimal width;

	/**
	 * depth of item.
	 */
	private BigDecimal depth;

	public Item() {

	}

	public Item(String name, String description, int cost, BigDecimal width, BigDecimal height,
			BigDecimal depth) {
		this.name = name;
		this.description = description;
		this.cost = cost;
		this.width = width;
		this.height = height;
		this.depth = depth;
	}

	@Id
	@NotNull
	@GeneratedValue(strategy = GenerationType.AUTO)
	public long getId() {
		return id;
	}

	@SuppressWarnings("unused")
	private void setId(final long id) {
		this.id = id;
	}

	@NotNull
	@NotBlank
	@Size(max = 40)
	public String getName() {
		return name;
	}

	public void setName(final String name) {
		this.name = name;
	}

	@NotNull
	@NotBlank
	@Size(max = 1024)
	public String getDescription() {
		return description;
	}

	public void setDescription(final String description) {
		this.description = description;
	}

	@NotNull
	@Min(0)
	public int getCost() {
		return cost;
	}

	public void setCost(int cost) {
		this.cost = Preconditions.checkNotNull(cost);
	}

	@NotNull
	@Min(0)
	public BigDecimal getHeight() {
		return height;
	}

	public void setHeight(final BigDecimal height) {
		this.height = Preconditions.checkNotNull(height);
	}

	@NotNull
	@Min(0)
	public BigDecimal getWidth() {
		return width;
	}

	public void setWidth(final BigDecimal width) {
		this.width = Preconditions.checkNotNull(width);
	}

	@NotNull
	@Min(0)
	public BigDecimal getDepth() {
		return depth;
	}

	public void setDepth(final BigDecimal depth) {
		this.depth = Preconditions.checkNotNull(depth);
	}

	@ElementCollection
	public Set<String> getImages() {
		return images;
	}

	// TODO настроить, чтобы hib образался напрямую к полям, а не через методы.
	@SuppressWarnings("unused")
	private void setImages(final Set<String> images) {
		this.images = images;
	}

	public String getMainImage() {
		return mainImage;
	}

	@NotNull
	@NotBlank
	public void setMainImage(final String mainImage) {
		this.mainImage = mainImage;
	}
}
